<template>
    <div class="dialog">
      <div class="dialog-con uploadContainer">
        <div class="flex-box">
          <p>上传文件</p>
          <p style="margin-right:20px;" @click="close"> <i class="iconfont">&#xe64f;</i></p>
        </div>
        <div class="upload">
          <el-upload
            class="upload-demo"
            action="/api/erp/v1/pur/upload/contract"
            :data="{id:id,userId:userId}"
            :on-success="onSuccess"
            :on-error="onError"
            multiple
            :file-list="fileList">
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
        </div>
      </div>
    </div>
</template>

<script>
  import {localStorage} from "js/localStorage"
    export default {
        name: "index.vue",
      data(){
          return {
            fileList:[],
            userId:''
          }
      },
      created(){
        this.userId=localStorage.get('userID')
      },
      props:{
          id:""
      },
      methods:{
        onSuccess(response, file, fileList){
          if (response.code === 'ERROR'){
            fileList.splice(fileList.length-1,1);
          }
          this.$message.success(response.msg)
        },
        onError(err, file, fileList){
            this.$message.error(err.msg)
        },
        close(){
          this.$emit("closeUpload")
        }
      }
    }
</script>

<style scoped lang="scss">
.uploadContainer{
  width:450px;
  height:450px;
  .upload{
     margin-left:20px;
  }
  .flex-box{
      display: flex;
      justify-content: space-between;
      line-height:45px;
      text-indent:20px;

  }
}
</style>
